package com.jo.cch.helper;

import android.content.Context;

import com.jo.cch.R;
import com.jo.cch.bean.LetterInfo;
import com.jo.cch.db.SpUtil;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class YingyuDataHelper {

    public static String key = "yingyuError";

    public static Map<String, String> letterChimeMap = new HashMap<>();

    public static Map<String,Map<String, List<LetterInfo>>> datas = new HashMap<String,Map<String, List<LetterInfo>>>();

    public static String[] dyy = {"[ɑ:]","[ɜ:]","[i:]","[ɔ:]","[u:]","[ʌ]","[ɪ]","[ɒ]","[ʊ]","[ə]","[e]","[æ]"};//12

    public static String[] syy = {"[ei]","[ai]","[ɔi]","[iə]","[ɛə]","[uə]","[au]","[əu]"};//8

    public static String[] fy = {"[p]","[b]","[t]","[d]","[k]","[g]","[f]","[v]","[s]","[z]","[θ]","[ð]","[ʃ]","[ʒ]","[tʃ]","[dʒ]","[tr]","[dr]","[ts]","[dz]","[m]","[n]","[ŋ]","[h]","[l]","[r]","[j]","[w]"};

    public static String[] zm = {"Aa","Bb","Cc","Dd","Ee","Ff","Gg","Hh","Ii","Jj","Kk","Ll","Mm","Nn","Oo","Pp","Qq","Rr","Ss","Tt","Uu","Vv","Ww","Xx","Yy","Zz"};

    public static String[] zmdx = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

    public static String[] zmxx = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

    static {
        //元音
        Map<String, List<LetterInfo>> yyMap = new HashMap<>();
        yyMap.put("单元音", createLetterList(dyy));
        yyMap.put("双元音", createLetterList(syy));
        datas.put("元音", yyMap);
        //辅音
        Map<String, List<LetterInfo>> fyMap = new HashMap<>();
        fyMap.put("辅音", createLetterList(fy));
        datas.put("辅音", fyMap);
        //字母
        Map<String, List<LetterInfo>> zmMap = new HashMap<>();
        zmMap.put("字母", createLetterList(zm));
        datas.put("字母", zmMap);

        letterChimeMap.put("[ɑ:]", "啊");
        letterChimeMap.put("[ɜ:]", "饿");
        letterChimeMap.put("[i:]", "依");
        letterChimeMap.put("[ɔ:]", "噢");
        letterChimeMap.put("[u:]", "乌");
        letterChimeMap.put("[ʌ]", "啊");
        letterChimeMap.put("[ɪ]", "依");
        letterChimeMap.put("[ɒ]", "噢");
        letterChimeMap.put("[ʊ]", "乌");
        letterChimeMap.put("[ə]", "饿");
        letterChimeMap.put("[e]", "哎");
        letterChimeMap.put("[æ]", "哎");

        letterChimeMap.put("[ei]", "艾依");
        letterChimeMap.put("[ai]", "啊依");
        letterChimeMap.put("[ɔi]", "噢依");
        letterChimeMap.put("[iə]", "依饿");
        letterChimeMap.put("[eə]", "艾饿");
        letterChimeMap.put("[uə]", "乌饿");
        letterChimeMap.put("[au]", "啊乌");
        letterChimeMap.put("[əu]", "饿乌");

        letterChimeMap.put("[p]", "破");
        letterChimeMap.put("[b]", "播");
        letterChimeMap.put("[t]", "特");
        letterChimeMap.put("[d]", "得");
        letterChimeMap.put("[k]", "克");
        letterChimeMap.put("[g]", "哥");
        letterChimeMap.put("[f]", "夫");
        letterChimeMap.put("[v]", "乌");
        letterChimeMap.put("[s]", "思");
        letterChimeMap.put("[z]", "字");
        letterChimeMap.put("[θ]", "思");
        letterChimeMap.put("[ð]", "字");
        letterChimeMap.put("[ʃ]", "湿");
        letterChimeMap.put("[ʒ]", "日");
        letterChimeMap.put("[tʃ]", "吃");
        letterChimeMap.put("[dʒ]", "支");
        letterChimeMap.put("[tr]", "戳");
        letterChimeMap.put("[dr]", "捉");
        letterChimeMap.put("[ts]", "测");
        letterChimeMap.put("[dz]", "则");
        letterChimeMap.put("[m]", "木");
        letterChimeMap.put("[n]", "呢");
        letterChimeMap.put("[ŋ]", "嗯");
        letterChimeMap.put("[h]", "喝");
        letterChimeMap.put("[l]", "乐");
        letterChimeMap.put("[r]", "弱");
        letterChimeMap.put("[j]", "耶");
        letterChimeMap.put("[w]", "我");

        letterChimeMap.put("A", "诶");
        letterChimeMap.put("B", "必");
        letterChimeMap.put("C", "细");
        letterChimeMap.put("D", "地");
        letterChimeMap.put("E", "意");
        letterChimeMap.put("F", "挨富");
        letterChimeMap.put("G", "寄");
        letterChimeMap.put("H", "诶吃");
        letterChimeMap.put("I", "啊爱");
        letterChimeMap.put("J", "捷");
        letterChimeMap.put("K", "克");
        letterChimeMap.put("L", "哎儿");
        letterChimeMap.put("M", "哎母");
        letterChimeMap.put("N", "恩");
        letterChimeMap.put("O", "欧");
        letterChimeMap.put("P", "批");
        letterChimeMap.put("Q", "可优");
        letterChimeMap.put("R", "阿");
        letterChimeMap.put("S", "哎死");
        letterChimeMap.put("T", "踢");
        letterChimeMap.put("U", "优");
        letterChimeMap.put("V", "微");
        letterChimeMap.put("W", "答不留");
        letterChimeMap.put("X", "爱克斯");
        letterChimeMap.put("Y", "歪");
        letterChimeMap.put("Z", "贼");

        letterChimeMap.put("a", "诶");
        letterChimeMap.put("b", "必");
        letterChimeMap.put("c", "细");
        letterChimeMap.put("d", "地");
        letterChimeMap.put("e", "意");
        letterChimeMap.put("f", "挨富");
        letterChimeMap.put("g", "寄");
        letterChimeMap.put("h", "诶吃");
        letterChimeMap.put("i", "啊爱");
        letterChimeMap.put("j", "捷");
        letterChimeMap.put("k", "克");
        letterChimeMap.put("l", "哎儿");
        letterChimeMap.put("m", "哎母");
        letterChimeMap.put("n", "恩");
        letterChimeMap.put("o", "欧");
        letterChimeMap.put("p", "批");
        letterChimeMap.put("q", "可优");
        letterChimeMap.put("r", "阿");
        letterChimeMap.put("s", "哎死");
        letterChimeMap.put("t", "踢");
        letterChimeMap.put("u", "优");
        letterChimeMap.put("v", "微");
        letterChimeMap.put("w", "答不留");
        letterChimeMap.put("x", "爱克斯");
        letterChimeMap.put("y", "歪");
        letterChimeMap.put("z", "贼");

        letterChimeMap.put("Aa", "诶");
        letterChimeMap.put("Bb", "必");
        letterChimeMap.put("Cc", "细");
        letterChimeMap.put("Dd", "地");
        letterChimeMap.put("Ee", "意");
        letterChimeMap.put("Ff", "挨富");
        letterChimeMap.put("Gg", "寄");
        letterChimeMap.put("Hh", "诶吃");
        letterChimeMap.put("Ii", "啊爱");
        letterChimeMap.put("Jj", "捷");
        letterChimeMap.put("Kk", "克");
        letterChimeMap.put("Ll", "哎儿");
        letterChimeMap.put("Mm", "哎母");
        letterChimeMap.put("Nn", "恩");
        letterChimeMap.put("Oo", "欧");
        letterChimeMap.put("Pp", "批");
        letterChimeMap.put("Qq", "可优");
        letterChimeMap.put("Rr", "阿");
        letterChimeMap.put("Ss", "哎死");
        letterChimeMap.put("Tt", "踢");
        letterChimeMap.put("Uu", "优");
        letterChimeMap.put("Vv", "微");
        letterChimeMap.put("Ww", "答不留");
        letterChimeMap.put("Xx", "爱克斯");
        letterChimeMap.put("Yy", "歪");
        letterChimeMap.put("Zz", "贼");

    }

    public static List<LetterInfo> getAllDatas(){
        List<LetterInfo> datas = createLetterList(dyy);
        datas.addAll(createLetterList(syy));
        datas.addAll(createLetterList(fy));
        datas.addAll(createLetterList(zm));
        return datas;
    }

    public static List<LetterInfo> getZmDatas(){
        List<LetterInfo> datas = createLetterList(zmdx);
        datas.addAll(createLetterList(zmxx));
        return datas;
    }

    public static List<LetterInfo> getDatas(Context context, String groupKey, String childKey){
        if("易错".equals(childKey)){
            return SpUtil.getInstance(context).getList(key, LetterInfo.class);
        }else{
            return datas.get(groupKey).get(childKey);
        }
    }

    private static List<LetterInfo> createLetterList(String[] letters){
        List<LetterInfo> rs = new ArrayList<>();
        for(String l : letters){
            rs.add(new LetterInfo(l, R.drawable.yesmark, false));
        }
        return rs;
    }

    public static void addErrorWord(Context context, String errorLetter){
        boolean flag = true;
        List<LetterInfo> list = SpUtil.getInstance(context).getList(key,LetterInfo.class);
        for(LetterInfo l : list){
            if(errorLetter.equals(l.getLetter())){
                flag = false;
                break;
            }
        }
        if(flag){
            list.add(new LetterInfo(errorLetter, R.drawable.yesmark,false));
        }
        SpUtil.getInstance(context).saveList(key,list);
    }

    public static String getWordByLetter(String letter){
        return letterChimeMap.get(letter);
    }
}
